home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / dev / amos / blox0_7.lha / score.Bak / score.amosSourceCode < prev   
AMOS Source Code  |  1980-09-18  |  4KB  |  210 lines

  1. '
  2. ' amospro high score routine 
  3. '
  4.  
  5.  
  6.  
  7.  
  8.  
  9. '  
  10. Dim NOM$(9),SCORE(9)
  11. Global NOM$(),SCORE()
  12. '
  13. '
  14. ' Small example
  15. '
  16. ' Close screen 0 (default) 
  17. ' Screen Close 0 
  18. '
  19. ' Load a list of scores from "Hiscores.SCR"  
  20. HISCORE_LOAD["Hiscores.SCR"]
  21. '
  22. HISCORE_ENTER[Val(Command Line$)]
  23. '
  24. ' Save the new table on the disc 
  25. HISCORE_SAVE["Hiscores.SCR"]
  26. '
  27. JW:
  28. A=Joy(1)
  29. If A>15 Then Goto JW2
  30. Goto JW
  31. JW2:
  32. '
  33. ' Finally, remove the hi-score table from the screen 
  34. HISCORE_REMOVE
  35. '
  36. Command Line$=Str$(SCORE(0))
  37. Run "blox"
  38.  
  39. '
  40. 'F9 (Fold/Unfold) displays the full listings 
  41. Procedure HISCORE_DISPLAY
  42.    '
  43.    Global SCR_FLG
  44.    '
  45.    Dim C(16)
  46.    '
  47.    ' Unpack the image into screen 7, and fade it down to black  
  48.    Unpack 10 To 7 : Screen Hide 
  49.    For C=0 To 15 : C(C)=Colour(C) : Colour C,0 : Next 
  50.    '
  51.    ' This internal flag is set to one if we have to   
  52.    ' enter the name. In this case, we just copy the 
  53.    ' ENTER YOUR NAME picture to the title area at the top of the screen 
  54.      If SCR_FLG
  55.        Screen Copy 7,80,72,240,120 To 7,80,8
  56.      End If 
  57.    '
  58.    ' Erase 'Enter your name' from the screen area   
  59.    Cls 0,80,72 To 240,120
  60.    '
  61.    ' Display the 10 names using a FOR..NEXT loop  
  62.    '  
  63.    Ink 1,0,0
  64.    For I=0 To 9
  65.       YP=82+I*9
  66.       SCORE$=Mid$(Str$(SCORE(I)),2)
  67.       LS=Text Length(SCORE$)
  68.       Text 85,YP,NOM$(I)
  69.       Text 251-LS,YP,SCORE$
  70.    Next I
  71.    '
  72.    ' Now we can fade in the screen
  73.    Screen Show 
  74.    '
  75.    ' Fade the screen back to the original colours 
  76.    Fade 1,C(0),C(1),C(2),C(3),C(4),C(5),C(6),C(7),C(8),C(9),C(10),C(11),C(12),C(13),C(14),C(15)
  77.    ' Wait until the fade is over
  78.    Wait 16
  79.    '
  80.    Pop Proc
  81.    '
  82. End Proc
  83. Procedure HISCORE_REMOVE
  84.    '
  85.    ' Simply fade out the screen to black, and erase it
  86.    Fade 1 : Wait 16
  87.    Screen Close 7
  88.    '
  89. End Proc
  90. Procedure HISCORE_ENTER[SCORE]
  91.    '
  92.    Global SCR_FLG
  93.    '
  94.    If SCORE>SCORE(9)
  95.       '
  96.       ' Find the position of our new score in the table
  97.       POS=0
  98.       While SCORE<=SCORE(POS)
  99.          POS=POS+1
  100.       Wend 
  101.       '  Move the lower scores one place down  
  102.       For I=9 To POS+1 Step -1
  103.          NOM$(I)=NOM$(I-1)
  104.          SCORE(I)=SCORE(I-1)
  105.       Next I
  106.       NOM$(POS)=""
  107.       SCORE(POS)=SCORE
  108.       '
  109.       ' Display score, with the ENTER YOUR NAME picture along the title
  110.       SCR_FLG=-1 : HISCORE_DISPLAY
  111.       '
  112.       ' Set up Cursor  
  113.       Flash 15,"(FFF,30)(666,20)"
  114.       XC=100 : YC=50
  115.       '
  116.       ' Display Cursor 
  117.       Gosub CURSEUR
  118.       '
  119.       ' Input the name using a REPEAT..UNTIL loop
  120.       Repeat 
  121.          ' Read keyboard  
  122.          K$=Inkey$
  123.          K=Asc(K$)
  124.          L=Len(NOM$)
  125.          ' Handle Backspace 
  126.          If K=8 and L>0
  127.             DC=0
  128.             XC=XC-8
  129.             Text XC,YC,"  "
  130.             Gosub CURSEUR
  131.             NOM$=Left$(NOM$,L-1)
  132.          End If 
  133.          ' Handle cursor  
  134.          If K>13 and L<12
  135.             DC=8
  136.             Ink 1 : Text XC,YC,K$
  137.             XC=XC+8
  138.             Gosub CURSEUR
  139.             NOM$=NOM$+K$
  140.          End If 
  141.          '
  142.          ' Repeat until a carriage return.  
  143.       Until K=13
  144.       '
  145.       ' Put the new name into the NOM$ array 
  146.       NOM$(POS)=NOM$
  147.       SCORE(POS)=SCORE
  148.       '
  149.       ' Erase screen 
  150.       Flash Off 
  151.       HISCORE_REMOVE
  152.       SCR_FLG=0
  153.       '
  154.    End If 
  155.    '
  156.    ' Display final array, and return! 
  157.    HISCORE_DISPLAY
  158.    '
  159.    Pop Proc
  160.    '
  161.    '  Simulate a 'fake' text cursor using the DRAW command  
  162.    CURSEUR:
  163.    Ink 15 : Draw XC,YC+1 To XC+6,YC+1
  164.    Return 
  165.    '
  166. End Proc
  167. Procedure HISCORE_LOAD[N$]
  168.    '
  169.    ' Handle errors
  170.    On Error Goto ERREUR
  171.    '
  172.    ' Open a simple sequential file
  173.    Open In 1,N$
  174.    ' Read the names and scores from the disc
  175.    For I=0 To 9
  176.       Line Input #1,NOM$(I),SCORE$
  177.       SCORE(I)=Val(SCORE$)
  178.    Next I
  179.    ' Close up the file  
  180.    Close 1
  181.    '
  182.    SKIP:
  183.    Pop Proc
  184.    '
  185.    ERREUR:
  186.    Resume SKIP
  187.    '
  188. End Proc
  189. Procedure HISCORE_SAVE[N$]
  190.    '
  191.    ' Handle errors
  192.    On Error Goto ERREUR
  193.    '
  194.    ' Create a simple sequential file  
  195.    Open Out 1,N$
  196.    ' Write the names and scores to the new file 
  197.    For I=0 To 9
  198.       Print #1,NOM$(I)
  199.       Print #1,Str$(SCORE(I))
  200.    Next I
  201.    ' Close the file (ESSENTIAL!)
  202.    Close 1
  203.    '
  204.    SKIP:
  205.    Pop Proc
  206.    '
  207.    ERREUR:
  208.    Resume SKIP
  209.    '
  210. End Proc